<div style="padding:20px;">
<? $defaultBespinOptions = ', "settings": {"fontsize": 10, "tabstop": 4, "theme": "white", "codecomplete": true, "autoindent": true}, "stealFocus": true'; ?>
<form id="hforml<?=(int)$arr_param["library"]["library_id"]?>" method="post" action="?event=builder:home" onsubmit="return false;">
	<label for="name">Name of Library</label><br/>
	<input type="text" id="lib_name_#library.library_id" name="library[name]" value="#library.name" /><br/><br/>
	
	<label for="codel<?=(int)$arr_param["library"]["library_id"]?>">Library Code:</label><br/>
	<input type="hidden" id="hCodel<?=(int)$arr_param["library"]["library_id"]?>" name="library[code]" value="" />
	<div style="border:1px solid #ccc;" rel="builder:editLibrary&refresh=code&library_id=<?=(int)$arr_param["library"]["library_id"]?>" id="codel<?=(int)$arr_param['library']['library_id']?>" data-bespinoptions='{"syntax": "php"<?=$defaultBespinOptions?>}'>#library.code</div>
	<div style="clear:both;"></div>
	<br/>
	<script type="text/javascript">
	//<![CDATA[
		setTimeout(function() {
			$("hforml<?=(int)$arr_param['library']['library_id']?>").save = function() {
		    	if (this.saving) return;
		    	this.saving = true;
		    	document.title = "Saving Library "+$("lib_name_#library.library_id").getValue()+"...";
				$('hCodel<?=(int)$arr_param["library"]["library_id"]?>').value=Builder.getCode("codel<?=(int)$arr_param['library']['library_id']?>");
				var me = this;
				invoke(null, 'builder:editLibrary&check=1&module_id=<?=$arr_param['library']['fk_module_id']?>&library_id=<?=(int)$arr_param['library']['library_id']?>', $('hforml<?=(int)$arr_param["library"]["library_id"]?>').serialize(), true, function(req) {
					me.saving = false;
					document.title = "Prails Home";
					Ext.ux.util.msg("Saving completed.", "Your changes have been saved successfully.");

					$("codel<?=(int)$arr_param['library']['library_id']?>").crc.content = Builder.getCode("codel<?=(int)$arr_param['library']['library_id']?>");
					$("codel<?=(int)$arr_param['library']['library_id']?>").dirty = false;

					if (<?=(int)$arr_param["library"]["library_id"]?> == 0) {
						var name = $("lib_name_#library.library_id").getValue();
						var id = req.responseText.split(/\s/g)[0];
						Builder.closeTab("l_0");
						var n = new Ext.tree.TreeNode({
							text: name,
							leaf: true,
							id: "l_"+id,
							allowChildren: false
						});
						Builder.libRoot.appendChild(n);
						Builder.editLibrary(n);
					}
				});
				return false;			
			};
			Builder.applyBespin("codel<?=(int)$arr_param['library']['library_id']?>", function(fr) {
				$("codel<?=(int)$arr_param['library']['library_id']?>").down("iframe").up().style.height = (parseInt($("hforml<?=(int)$arr_param['library']['library_id']?>").parentNode.parentNode.style.height) - 150) + "px";				

				fr.txt.addKeywords(null, function(txt) {
        			var res = ["$_GET", "$_POST", "$_REQUEST", "$_COOKIE", "$_SERVER"];
        			var matches = txt.value.substr(0, txt.selectionEnd).match(/\$[a-zA-Z_][a-zA-Z_0-9]*\b/gi);
        			if (matches) {
	        			for (var a = 0; a < matches.length; a++) {
	        				if ((",$_GET,$_POST,$_REQUEST,$_COOKIE,$_SERVER,"+res.join(",")+",").indexOf(matches[a]) < 0) {
	        					res.push(matches[a]);
	        				}
	        			}
        			}
        			return res;
				});
				fr.txt.addKeywords(null, ["invoke($event, $arr_param)", "checkFields($arr_toCheck, $arr_keys)", "scaleEmbed($embed, $width, $height)", "isEmbed($embed)", "isExternalURL($string)", "if_set($a, $b)", "set_var($a, $b)", "getUserLanguage($arr_allowedLanguages, $defaultLanguage)", "wordCut($text, 200, \"...\")", "removeDir($path, true)", "hyperlink($text)", "timeDiff($time)", "toUTF8($string)", "jumpTo($url)", "createThumbnail($src, $dest, 64, 64)", "getThumbnailFromEmbed($embed)", "sendMail($to, $subject, $content, $fromName, $fromAddress)", "doGet($url)", "doPost($url, $postData)", "array_merge_recursive_distinct($arr1, $arr2)", "one_of($a, $b, ...)", "receiveFile($fileName, $targetPath)"]);

			}, Object.extend(Builder.prailsNamespace, {
	        	save: function() {
	            	parent.$("hforml<?=(int)$arr_param['library']['library_id']?>").save();
	          	}
	      	}));
			
			Ext.getCmp("portlet_content_l_<?=(int)$arr_param['library']['library_id']?>").getTopToolbar().add([{
				xtype: "button",
				text: "Save",
				iconCls: "save",
				handler: function(e) {
					$("hforml<?=(int)$arr_param['library']['library_id']?>").save();
				}
			},"-"]);
			Ext.getCmp("portlet_content_l_<?=(int)$arr_param['library']['library_id']?>").getTopToolbar().doLayout();
		}, 100);
	//]]>
	</script>
</form>
</div>